observations
Class Quantity

java.lang.Object
  extended byobservations.Quantity
Direct Known Subclasses:
NullQuantity

public class Quantity
extends java.lang.Object

Quantity Represents a value such as 6 feet or 5 $. It's part of Fowler's pattern 'Quantity'.

Version:
2004-09-10
Author:
Sascha Hemminger

Constructor Summary
Quantity(double amount, Unit unit)
          Basic constructor used by all other constructors.
Quantity(int amount, Unit unit)
          Same as basic constructor, but value given as integer.
Quantity(java.lang.String amountString, Unit unit)
          Parses the given string and calls basic constructor.
 
Method Summary
 boolean equals(Quantity arg)
          Tests if this quantity equals the argument (this == arg).
 double getAmount()
          Get the quantity's numeric value.
 java.lang.String getAmountString()
          Gives a string representation of the quantity's value.
 Unit getUnit()
          Get this quantity's unit.
 boolean isGreaterThan(Quantity arg)
          Tests if this quantity is greater than argument (this > arg).
 boolean isGreaterThanOrEqualTo(Quantity arg)
          Tests if this quantity is greater than or equal to argument (this >= arg).
 boolean isLessThan(Quantity arg)
          Tests if this quantity is less than the argument (this < arg).
 boolean isLessThanOrEqualTo(Quantity arg)
          Tests if this quantity is less than or equal to argument (this <= arg).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Quantity

public Quantity(double amount,
                Unit unit)
Basic constructor used by all other constructors.

Parameters:
amount - numeric value of the quantity
unit - the unit (eg. $)

Quantity

public Quantity(int amount,
                Unit unit)
Same as basic constructor, but value given as integer.

Parameters:
amount - numeric integer value
unit - the unit (eg. $)
See Also:
Quantity(double, Unit)

Quantity

public Quantity(java.lang.String amountString,
                Unit unit)
Parses the given string and calls basic constructor.

Parameters:
amountString - string representation of a numeric value
unit - the unit (eg. $)
See Also:
Quantity(double, Unit)
Method Detail

equals

public boolean equals(Quantity arg)
Tests if this quantity equals the argument (this == arg).

Parameters:
arg - other quantity
Returns:
true if both quantities equal

getAmount

public double getAmount()
Get the quantity's numeric value.

Returns:
numeric value

getAmountString

public java.lang.String getAmountString()
Gives a string representation of the quantity's value.

Returns:
value as a string

getUnit

public Unit getUnit()
Get this quantity's unit.

Returns:
the unit

isGreaterThan

public boolean isGreaterThan(Quantity arg)
Tests if this quantity is greater than argument (this > arg).

Parameters:
arg - other quantity
Returns:
true if this is greater than argument

isGreaterThanOrEqualTo

public boolean isGreaterThanOrEqualTo(Quantity arg)
Tests if this quantity is greater than or equal to argument (this >= arg).

Parameters:
arg - other quantity
Returns:
true if this is greater than or equal to argument

isLessThan

public boolean isLessThan(Quantity arg)
Tests if this quantity is less than the argument (this < arg).

Parameters:
arg - other quantity
Returns:
true if this is less than argument

isLessThanOrEqualTo

public boolean isLessThanOrEqualTo(Quantity arg)
Tests if this quantity is less than or equal to argument (this <= arg).

Parameters:
arg - other quantity
Returns:
true if this is less than or equal to argument